from selenium.webdriver.common.by import By
from page.base_page_helin import BasePage
class AddYfkPage(BasePage):
    # 进入添加应付款页面定位器
    cw_locator=(By.LINK_TEXT,"财务")
    yfk_locator=(By.LINK_TEXT,"应付款")
    tjyfk_locator=(By.LINK_TEXT,"添加应付款")

    # 添加应付款定位器
    yfkm_locator=(By.ID,'name')

    ht_locator=(By.ID,"contract_name")
    xzht_table_locator=(By.XPATH,'//*[@id="data"]')
    qd_ht_locator=(By.XPATH,"/html/body/div[8]/div[3]/div/button[1]/span")

    kh_locator=(By.ID,"customer")
    xzkh_table_locator=(By.ID,"datas")
    qd_kh_locator=(By.XPATH,"/html/body/div[7]/div[3]/div/button[1]/span")

    fzr_locator=(By.ID,"owner_name")
    xzfzr_locator=(By.ID,"d_content")
    qdfzr_locator=(By.XPATH,"/html/body/div[9]/div[3]/div/button[1]")

    yfje_locator=(By.ID,"price")

    fkd_locator=(By.ID,"check_add_order")
    fkdje_locator=(By.ID,"order_money")
    fkdsj_locator=(By.CSS_SELECTOR,"#add_order > tbody > tr:nth-child(3) > td:nth-child(2) > input[type=text]")
    fkdzt_selector=(By.XPATH,'//*[@id="add_order"]/tbody/tr[4]/td[2]')

    fksj_locator=(By.ID,"pay_time")
    ms_locator=(By.CSS_SELECTOR,"body > div.container > div.row > div > form > table > tbody > tr:nth-child(9) > td:nth-child(2) > textarea")
    bc_locator=(By.XPATH,'/html/body/div[5]/div[2]/div/form/table/tfoot/tr/td[2]/input[1]')

    # 进入添加应付款单页面
    def click_cw(self):
        self.driver.find_element(*self.cw_locator).click()

    def click_yfk(self):
        self.driver.find_element(*self.yfk_locator).click()

    def click_tjyfk(self):
        self.driver.find_element(*self.tjyfk_locator).click()

    # 添加应付款
    def add_yfkm(self,yfkm):
        self.driver.find_element(*self.yfkm_locator).send_keys(yfkm)

    def add_ht(self):
        self.driver.find_element(*self.ht_locator).click()

    def add_xzht(self,httb):
        tbody=self.driver.find_element(*self.xzht_table_locator)
        trs=tbody.find_elements(By.TAG_NAME,"tr")
        for tr in trs:
            tds=tr.find_elements(By.TAG_NAME,"td")
            if tds[3].text==httb:
                tds[0].find_element(By.CSS_SELECTOR,"input[name='contract']").click()
                break
        self.driver.find_element(*self.qd_ht_locator).click()

    def add_kh(self,htmc):
        self.driver.find_element(*self.kh_locator).click()
        tbody=self.driver.find_element(*self.xzkh_table_locator)
        trs=tbody.find_elements(By.TAG_NAME,"tr")
        for tr in trs:
            tds=tr.find_elements(By.TAG_NAME,"td")
            if tds[1].text==htmc:
                tds[0].click()
                break
        self.driver.find_element(*self.qd_kh_locator).click()

    def add_fzr(self,fzr):
        self.driver.find_element(*self.fzr_locator).click()
        tbody=self.driver.find_element(*self.xzfzr_locator)
        trs=tbody.find_elements(By.TAG_NAME,"tr")
        for tr in trs:
            tds=tr.find_elements(By.TAG_NAME,"td")
            if tds[1].text==fzr:
                tds[0].click()
                break
        self.driver.find_element(*self.qdfzr_locator).click()

    def add_yfje(self,yfje):
        self.driver.find_element(*self.yfje_locator).clear()
        self.driver.find_element(*self.yfje_locator).send_keys(yfje)

    def add_fkd(self):
        self.driver.find_element(*self.fkd_locator).click()

    def add_fkdje(self,fkdje):
        self.driver.find_element(*self.fkdje_locator).send_keys(fkdje)

    def add_fkdsj(self,fkdsj):
        self.driver.find_element(*self.fkdsj_locator).send_keys(fkdsj)

    def add_fkdzt(self):
        self.driver.find_elements(*self.fkdzt_selector)[0].click()

    def add_fksj(self,fksj):
        self.driver.find_element(*self.fksj_locator).send_keys(fksj)

    def add_ms(self,ms):
        self.driver.find_element(*self.ms_locator).send_keys(ms)

    def add_bc(self):
        self.driver.find_element(*self.bc_locator).click()
